<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浏览器的本地存储</title>
</head>
<body>
    <button id="btn">存储</button>
    <button id="btn2">获取</button>
    <button id="btn3">删除</button>
    <button id="btn4">清除</button>
    <script>
        btn.onclick = function(){
            localStorage.setItem("name", "陈志攀")
            localStorage.setItem("age", 100)
            localStorage.setItem("user", JSON.stringify({name: "陈志攀", age: 33}))

            sessionStorage.setItem("name", "陈志攀")
            sessionStorage.setItem("age", 100)
            sessionStorage.setItem("user", JSON.stringify({name: "陈志攀", age: 33}))
        }
        btn2.onclick = function(){
            console.log(localStorage.getItem("name"))
            console.log(localStorage.getItem("age"))
            console.log(JSON.parse(localStorage.getItem("user")))

            console.log(sessionStorage.getItem("name"))
            console.log(sessionStorage.getItem("age"))
            console.log(JSON.parse(sessionStorage.getItem("user")))
        }
        btn3.onclick = function(){
            localStorage.removeItem("name")
            sessionStorage.removeItem("name")
        }
        btn4.onclick = function(){
            localStorage.clear()
            sessionStorage.clear()
        }
    </script>
</body>
</html>